#include <QByteArray>
#include <QXmlAttributes>
#include <QXmlStreamReader>
#include <QString>
#include <QDebug>
#include <QDateTime>
#include <QDebug>

#include "_Interface/_global_datastruct.h"
#include "backinstance.h"
#include "Package/oxfordlasersensordll_global.h"
#include "Package/simpletcpsocketdll_global.h"
#include "Package/SimpleRoboticMath/ConsoleMain/simpleroboticmath.h"

backinstance::backinstance(){
    this->pOxfordLaserSensor = GetOxfordLaserSensorInstance();
    WorkModel = ENUM_WorkModel::Null;
    WorkType = ENUM_WorkType::Mannual;

    pRobotDAQData = new ST_RobotDAQData;
    pSeamFindingData = new ST_SeamFindingData;
    pHand2EyesMatrix = new ST_Hand2EyesMatrix;
    pLaserSensorData = new ST_LaserSensorData;
    pButtonStatus = new ST_ButtonStatus;

    this->mDataSaveParam.SaveFlagLast = false;
    this->pLaserSensorData->bConnected = false;
    this->pRobotDAQData->bConnected = false;

    this->pLaserSensorData->bRecord = false;
    this->pLaserSensorData->bRecording = false;
    this->pSeamFindingData->EndPointDone = false;
    this->pSeamFindingData->StartPointDone = false;

    int i = 0;
    for(i = 0; i < 6; i++){
        this->Hand2EyesCalibrationData[i].bUsed = false;
    }

}

backinstance::~backinstance(){
    pOxfordLaserSensor->~OxfordLaserSensorDLL();
    COM_disConnectToServer(this->EKRLClient);
    delete pRobotDAQData;
    delete pSeamFindingData;
    delete pHand2EyesMatrix;
    delete pLaserSensorData;
    delete pButtonStatus;
}

void backinstance::onbtnClickedSensorConnect(){
    pOxfordLaserSensor->LaserSensorConnect("127.0.0.1");
    this->pLaserSensorData->bFirstConnected = true;
    this->pLaserSensorData->bConnected = true;
}

void backinstance::onbtnClickedRobotTCPConnect(){
    COM_addTcpClient("192.168.100.30",54600,this->EKRLClient);
    COM_connectToServer(this->EKRLClient);
    this->pRobotDAQData->bConnected = true;
    this->pRobotDAQData->bFirstConnected = true;
}

void backinstance::onbtnClickedRobotUDPConnect(){

}

void backinstance::onbtnClickedTaskNull(){
    this->WorkModel = ENUM_WorkModel::Null;
}

void backinstance::onbtnClickedCalibration(){
    int i = 0;
    this->WorkModel = ENUM_WorkModel::Calibration;
    for(i = 0; i < 6; i++){
        this->Hand2EyesCalibrationData[i].bUsed = false;
    }
}

void backinstance::onbtnClickedSeamFinding(){
    this->WorkModel = ENUM_WorkModel::SeamFinding;

    this->pSeamFindingData->StartPos[0] = 0;
    this->pSeamFindingData->StartPos[1] = 0;
    this->pSeamFindingData->StartPos[2] = 0;

    this->pSeamFindingData->EndPos[0] = 0;
    this->pSeamFindingData->EndPos[1] = 0;
    this->pSeamFindingData->EndPos[2] = 0;

    this->pSeamFindingData->toRobotMove = 0;
}

void backinstance::onbtnClickedSeamFindingStart2End(){
    this->WorkModel = ENUM_WorkModel::SeamFindingStart2End;

    this->pSeamFindingData->StartPos[0] = 0;
    this->pSeamFindingData->StartPos[1] = 0;
    this->pSeamFindingData->StartPos[2] = 0;

    this->pSeamFindingData->EndPos[0] = 0;
    this->pSeamFindingData->EndPos[1] = 0;
    this->pSeamFindingData->EndPos[2] = 0;

    this->pSeamFindingData->toRobotMove = 0;
}

void backinstance::onbtnClickedSeamTracking(){
    this->WorkModel = ENUM_WorkModel::SeamTracking;
}

void backinstance::onbtnClickedCalPos1(){
    this->Hand2EyesCalibrationData[0].bUsed = true;
    this->Hand2EyesCalibrationData[0].Rx = this->pRobotDAQData->KRLRobotPos[0];
    this->Hand2EyesCalibrationData[0].Ry = this->pRobotDAQData->KRLRobotPos[1];
    this->Hand2EyesCalibrationData[0].Rz = this->pRobotDAQData->KRLRobotPos[2];
    this->Hand2EyesCalibrationData[0].Ra = this->pRobotDAQData->KRLRobotPos[3];
    this->Hand2EyesCalibrationData[0].Rb = this->pRobotDAQData->KRLRobotPos[4];
    this->Hand2EyesCalibrationData[0].Rc = this->pRobotDAQData->KRLRobotPos[5];

    this->Hand2EyesCalibrationData[0].Ly = this->pLaserSensorData->y;
    this->Hand2EyesCalibrationData[0].Lz = this->pLaserSensorData->z;

    double tempPosXYZ[3];
    double tempEulerZYX[3];

    tempPosXYZ[0] = this->Hand2EyesCalibrationData[0].Rx;
    tempPosXYZ[1] = this->Hand2EyesCalibrationData[0].Ry;
    tempPosXYZ[2] = this->Hand2EyesCalibrationData[0].Rz;

    tempEulerZYX[0] = this->Hand2EyesCalibrationData[0].Ra;
    tempEulerZYX[1] = this->Hand2EyesCalibrationData[0].Rb;
    tempEulerZYX[2] = this->Hand2EyesCalibrationData[0].Rc;

    EulerZYX2d4Matrix(tempPosXYZ,tempEulerZYX,this->Hand2EyesCalibrationData[0].mRobotMatrix);

    tempPosXYZ[0] = 0;
    tempPosXYZ[1] = this->Hand2EyesCalibrationData[0].Ly;
    tempPosXYZ[2] = this->Hand2EyesCalibrationData[0].Lz;

    tempEulerZYX[0] = 0;
    tempEulerZYX[1] = 0;
    tempEulerZYX[2] = 0;

    EulerZYX2d4Matrix(tempPosXYZ,tempEulerZYX,this->Hand2EyesCalibrationData[0].mLaserMatrix);
}

void backinstance::onbtnClickedCalPos2(){
    this->Hand2EyesCalibrationData[1].bUsed = true;
    this->Hand2EyesCalibrationData[1].Rx = this->pRobotDAQData->KRLRobotPos[0];
    this->Hand2EyesCalibrationData[1].Ry = this->pRobotDAQData->KRLRobotPos[1];
    this->Hand2EyesCalibrationData[1].Rz = this->pRobotDAQData->KRLRobotPos[2];
    this->Hand2EyesCalibrationData[1].Ra = this->pRobotDAQData->KRLRobotPos[3];
    this->Hand2EyesCalibrationData[1].Rb = this->pRobotDAQData->KRLRobotPos[4];
    this->Hand2EyesCalibrationData[1].Rc = this->pRobotDAQData->KRLRobotPos[5];

    this->Hand2EyesCalibrationData[1].Ly = this->pLaserSensorData->y;
    this->Hand2EyesCalibrationData[1].Lz = this->pLaserSensorData->z;

    double tempPosXYZ[3];
    double tempEulerZYX[3];

    tempPosXYZ[0] = this->Hand2EyesCalibrationData[1].Rx;
    tempPosXYZ[1] = this->Hand2EyesCalibrationData[1].Ry;
    tempPosXYZ[2] = this->Hand2EyesCalibrationData[1].Rz;

    tempEulerZYX[0] = this->Hand2EyesCalibrationData[1].Ra;
    tempEulerZYX[1] = this->Hand2EyesCalibrationData[1].Rb;
    tempEulerZYX[2] = this->Hand2EyesCalibrationData[1].Rc;

    EulerZYX2d4Matrix(tempPosXYZ,tempEulerZYX,this->Hand2EyesCalibrationData[1].mRobotMatrix);

    tempPosXYZ[0] = 0;
    tempPosXYZ[1] = this->Hand2EyesCalibrationData[1].Ly;
    tempPosXYZ[2] = this->Hand2EyesCalibrationData[1].Lz;

    tempEulerZYX[0] = 0;
    tempEulerZYX[1] = 0;
    tempEulerZYX[2] = 0;

    EulerZYX2d4Matrix(tempPosXYZ,tempEulerZYX,this->Hand2EyesCalibrationData[1].mLaserMatrix);
}

void backinstance::onbtnClickedCalPos3(){
    this->Hand2EyesCalibrationData[2].bUsed = true;
    this->Hand2EyesCalibrationData[2].Rx = this->pRobotDAQData->KRLRobotPos[0];
    this->Hand2EyesCalibrationData[2].Ry = this->pRobotDAQData->KRLRobotPos[1];
    this->Hand2EyesCalibrationData[2].Rz = this->pRobotDAQData->KRLRobotPos[2];
    this->Hand2EyesCalibrationData[2].Ra = this->pRobotDAQData->KRLRobotPos[3];
    this->Hand2EyesCalibrationData[2].Rb = this->pRobotDAQData->KRLRobotPos[4];
    this->Hand2EyesCalibrationData[2].Rc = this->pRobotDAQData->KRLRobotPos[5];

    this->Hand2EyesCalibrationData[2].Ly = this->pLaserSensorData->y;
    this->Hand2EyesCalibrationData[2].Lz = this->pLaserSensorData->z;

    double tempPosXYZ[3];
    double tempEulerZYX[3];

    tempPosXYZ[0] = this->Hand2EyesCalibrationData[2].Rx;
    tempPosXYZ[1] = this->Hand2EyesCalibrationData[2].Ry;
    tempPosXYZ[2] = this->Hand2EyesCalibrationData[2].Rz;

    tempEulerZYX[0] = this->Hand2EyesCalibrationData[2].Ra;
    tempEulerZYX[1] = this->Hand2EyesCalibrationData[2].Rb;
    tempEulerZYX[2] = this->Hand2EyesCalibrationData[2].Rc;

    EulerZYX2d4Matrix(tempPosXYZ,tempEulerZYX,this->Hand2EyesCalibrationData[2].mRobotMatrix);

    tempPosXYZ[0] = 0;
    tempPosXYZ[1] = this->Hand2EyesCalibrationData[2].Ly;
    tempPosXYZ[2] = this->Hand2EyesCalibrationData[2].Lz;

    tempEulerZYX[0] = 0;
    tempEulerZYX[1] = 0;
    tempEulerZYX[2] = 0;

    EulerZYX2d4Matrix(tempPosXYZ,tempEulerZYX,this->Hand2EyesCalibrationData[2].mLaserMatrix);
}

void backinstance::onbtnClickedCalPos4(){
    this->Hand2EyesCalibrationData[3].bUsed = true;
    this->Hand2EyesCalibrationData[3].Rx = this->pRobotDAQData->KRLRobotPos[0];
    this->Hand2EyesCalibrationData[3].Ry = this->pRobotDAQData->KRLRobotPos[1];
    this->Hand2EyesCalibrationData[3].Rz = this->pRobotDAQData->KRLRobotPos[2];
    this->Hand2EyesCalibrationData[3].Ra = 0;
    this->Hand2EyesCalibrationData[3].Rb = 0;
    this->Hand2EyesCalibrationData[3].Rc = 0;

    double tempPosXYZ[3];
    double tempEulerZYX[3];

    tempPosXYZ[0] = this->Hand2EyesCalibrationData[3].Rx;
    tempPosXYZ[1] = this->Hand2EyesCalibrationData[3].Ry;
    tempPosXYZ[2] = this->Hand2EyesCalibrationData[3].Rz;

    tempEulerZYX[0] = this->Hand2EyesCalibrationData[3].Ra;
    tempEulerZYX[1] = this->Hand2EyesCalibrationData[3].Rb;
    tempEulerZYX[2] = this->Hand2EyesCalibrationData[3].Rc;

    EulerZYX2d4Matrix(tempPosXYZ,tempEulerZYX,this->Hand2EyesCalibrationData[3].mRobotMatrix);
}

void backinstance::onbtnClickedCalPos5(){
    this->Hand2EyesCalibrationData[4].bUsed = true;
    this->Hand2EyesCalibrationData[4].Rx = this->pRobotDAQData->KRLRobotPos[0];
    this->Hand2EyesCalibrationData[4].Ry = this->pRobotDAQData->KRLRobotPos[1];
    this->Hand2EyesCalibrationData[4].Rz = this->pRobotDAQData->KRLRobotPos[2];
    this->Hand2EyesCalibrationData[4].Ra = 0;
    this->Hand2EyesCalibrationData[4].Rb = 0;
    this->Hand2EyesCalibrationData[4].Rc = 0;

    double tempPosXYZ[3];
    double tempEulerZYX[3];

    tempPosXYZ[0] = this->Hand2EyesCalibrationData[4].Rx;
    tempPosXYZ[1] = this->Hand2EyesCalibrationData[4].Ry;
    tempPosXYZ[2] = this->Hand2EyesCalibrationData[4].Rz;

    tempEulerZYX[0] = this->Hand2EyesCalibrationData[4].Ra;
    tempEulerZYX[1] = this->Hand2EyesCalibrationData[4].Rb;
    tempEulerZYX[2] = this->Hand2EyesCalibrationData[4].Rc;

    EulerZYX2d4Matrix(tempPosXYZ,tempEulerZYX,this->Hand2EyesCalibrationData[4].mRobotMatrix);
}

void backinstance::onbtnClickedCalPos6(){
    this->Hand2EyesCalibrationData[5].bUsed = true;
    this->Hand2EyesCalibrationData[5].Rx = this->pRobotDAQData->KRLRobotPos[0];
    this->Hand2EyesCalibrationData[5].Ry = this->pRobotDAQData->KRLRobotPos[1];
    this->Hand2EyesCalibrationData[5].Rz = this->pRobotDAQData->KRLRobotPos[2];
    this->Hand2EyesCalibrationData[5].Ra = 0;
    this->Hand2EyesCalibrationData[5].Rb = 0;
    this->Hand2EyesCalibrationData[5].Rc = 0;

    double tempPosXYZ[3];
    double tempEulerZYX[3];

    tempPosXYZ[0] = this->Hand2EyesCalibrationData[5].Rx;
    tempPosXYZ[1] = this->Hand2EyesCalibrationData[5].Ry;
    tempPosXYZ[2] = this->Hand2EyesCalibrationData[5].Rz;

    tempEulerZYX[0] = this->Hand2EyesCalibrationData[5].Ra;
    tempEulerZYX[1] = this->Hand2EyesCalibrationData[5].Rb;
    tempEulerZYX[2] = this->Hand2EyesCalibrationData[5].Rc;

    EulerZYX2d4Matrix(tempPosXYZ,tempEulerZYX,this->Hand2EyesCalibrationData[5].mRobotMatrix);
}

void backinstance::onbtnClickedCalibrationDo(double &X, double &Y, double &Z, double &A, double &B, double &C){
    int i;
    int j;
    int k;

    double InerseMatrix[4][4];
    double InerseMatrix2[4][4];

    double Hand2Eyes1[4][4];
    double Hand2Eyes11[4][4];

    double Hand2Eyes2[4][4];
    double Hand2Eyes22[4][4];

    double Hand2Eyes3[4][4];
    double Hand2Eyes33[4][4];

    double Hand2Eyessum1[4][4];
    double Hand2Eyessum2[4][4];


    for(i = 0; i < 4; i++){
        for(j = 0; j < 4; j++){
            Hand2Eyes11[i][j] = 0;
            Hand2Eyes22[i][j] = 0;
            Hand2Eyes33[i][j] = 0;
        }
    }

    for(i = 0; i < 4; i++){
        Hand2Eyes11[i][i] = 1;
        Hand2Eyes22[i][i] = 1;
        Hand2Eyes33[i][i] = 1;
    }

    k = 0;

    if(this->Hand2EyesCalibrationData[0].bUsed == true && this->Hand2EyesCalibrationData[3].bUsed){
        d4MatrixInverse(this->Hand2EyesCalibrationData[0].mRobotMatrix,InerseMatrix);
        d4MatrixInverse(this->Hand2EyesCalibrationData[0].mLaserMatrix,InerseMatrix2);

        d4MatrixMultiply(InerseMatrix,this->Hand2EyesCalibrationData[3].mRobotMatrix,Hand2Eyes1);
        d4MatrixMultiply(Hand2Eyes1,InerseMatrix2,Hand2Eyes11);
        k = 1;
    }else{}

    if(this->Hand2EyesCalibrationData[1].bUsed == true && this->Hand2EyesCalibrationData[4].bUsed){
        d4MatrixInverse(this->Hand2EyesCalibrationData[1].mRobotMatrix,InerseMatrix);
        d4MatrixInverse(this->Hand2EyesCalibrationData[1].mLaserMatrix,InerseMatrix2);

        d4MatrixMultiply(InerseMatrix,this->Hand2EyesCalibrationData[4].mRobotMatrix,Hand2Eyes2);
        d4MatrixMultiply(Hand2Eyes2,InerseMatrix2,Hand2Eyes22);
        k = 2;
    }else{}

    if(this->Hand2EyesCalibrationData[2].bUsed == true && this->Hand2EyesCalibrationData[5].bUsed){
        d4MatrixInverse(this->Hand2EyesCalibrationData[2].mRobotMatrix,InerseMatrix);
        d4MatrixInverse(this->Hand2EyesCalibrationData[2].mLaserMatrix,InerseMatrix2);

        d4MatrixMultiply(InerseMatrix,this->Hand2EyesCalibrationData[5].mRobotMatrix,Hand2Eyes3);
        d4MatrixMultiply(Hand2Eyes3,InerseMatrix2,Hand2Eyes33);
        k = 3;
    }else{}

    if( k == 1){
        for(i = 0; i < 4; i++){
            for(j = 0; j < 4; j++){
                this->pHand2EyesMatrix->mMatrix[i][j] = Hand2Eyes11[i][j];
            }
        }
    }
    else if( k == 2){
        d4MatrixPlus(Hand2Eyes11,Hand2Eyes22,Hand2Eyessum1);
        for(i = 0; i < 4; i++){
            for(j = 0; j < 4; j++){
                this->pHand2EyesMatrix->mMatrix[i][j] = Hand2Eyessum1[i][j] / 2;
            }
        }
    }
    else if( k == 3){
        d4MatrixPlus(Hand2Eyes11,Hand2Eyes22,Hand2Eyessum1);
        d4MatrixPlus(Hand2Eyessum1,Hand2Eyes33,Hand2Eyessum2);
        for(i = 0; i < 4; i++){
            for(j = 0; j < 4; j++){
                this->pHand2EyesMatrix->mMatrix[i][j] = Hand2Eyessum2[i][j] / 3;
            }
        }
    }


    if(k != 0){

        double tempPosXYZ[3];
        double tempEulerZYX[3];

        d4Matrix2EulerZYX(this->pHand2EyesMatrix->mMatrix,tempPosXYZ,tempEulerZYX);


        this->pHand2EyesMatrix->x = tempPosXYZ[0];
        this->pHand2EyesMatrix->y = tempPosXYZ[1];
        this->pHand2EyesMatrix->z = tempPosXYZ[2];

        this->pHand2EyesMatrix->a = tempEulerZYX[0];
        this->pHand2EyesMatrix->b = tempEulerZYX[1];
        this->pHand2EyesMatrix->c = tempEulerZYX[2];

    }
    else{
        this->pHand2EyesMatrix->x = 0;
        this->pHand2EyesMatrix->y = 0;
        this->pHand2EyesMatrix->z = 0;

        this->pHand2EyesMatrix->a = 0;
        this->pHand2EyesMatrix->b = 0;
        this->pHand2EyesMatrix->c = 0;
    }

    X = this->pHand2EyesMatrix->x;
    Y = this->pHand2EyesMatrix->y;
    Z = this->pHand2EyesMatrix->z;

    A = this->pHand2EyesMatrix->a;
    B = this->pHand2EyesMatrix->b;
    C = this->pHand2EyesMatrix->c;
}

void backinstance::onbtnClickedCalibrationSave(double Hand2EyePosition[6]){

    double tempPosXYZ[3];
    double tempEulerZYX[3];

    this->pHand2EyesMatrix->x = Hand2EyePosition[0];
    this->pHand2EyesMatrix->y = Hand2EyePosition[1];
    this->pHand2EyesMatrix->z = Hand2EyePosition[2];

    this->pHand2EyesMatrix->a = Hand2EyePosition[3];
    this->pHand2EyesMatrix->b = Hand2EyePosition[4];
    this->pHand2EyesMatrix->c = Hand2EyePosition[5];

    tempPosXYZ[0] = Hand2EyePosition[0];
    tempPosXYZ[1] = Hand2EyePosition[1];
    tempPosXYZ[2] = Hand2EyePosition[2];

    tempEulerZYX[0] = Hand2EyePosition[3];
    tempEulerZYX[1] = Hand2EyePosition[4];
    tempEulerZYX[2] = Hand2EyePosition[5];

    EulerZYX2d4Matrix(tempPosXYZ,tempEulerZYX,this->pHand2EyesMatrix->mMatrix);

}

void backinstance::onbtnClickedCalibrationReset(){
    int i = 0;
    int j = 0;
    for(i = 0; i < 4; i++){
        for(j = 0; j < 4; j++){
            this->Hand2EyesCalibrationData[0].mRobotMatrix[i][j] = 0;
            this->Hand2EyesCalibrationData[1].mRobotMatrix[i][j] = 0;
            this->Hand2EyesCalibrationData[2].mRobotMatrix[i][j] = 0;
            this->Hand2EyesCalibrationData[3].mRobotMatrix[i][j] = 0;
            this->Hand2EyesCalibrationData[4].mRobotMatrix[i][j] = 0;
            this->Hand2EyesCalibrationData[5].mRobotMatrix[i][j] = 0;

            this->Hand2EyesCalibrationData[0].mLaserMatrix[i][j] = 0;
            this->Hand2EyesCalibrationData[1].mLaserMatrix[i][j] = 0;
            this->Hand2EyesCalibrationData[2].mLaserMatrix[i][j] = 0;
            this->Hand2EyesCalibrationData[3].mLaserMatrix[i][j] = 0;
            this->Hand2EyesCalibrationData[4].mLaserMatrix[i][j] = 0;
            this->Hand2EyesCalibrationData[5].mLaserMatrix[i][j] = 0;

            this->pHand2EyesMatrix->mMatrix[i][j] = 0;
        }
    }

    this->pButtonStatus->CalPos1 = false;
    this->pButtonStatus->CalPos2 = false;
    this->pButtonStatus->CalPos3 = false;
    this->pButtonStatus->CalPos4 = false;
    this->pButtonStatus->CalPos5 = false;
    this->pButtonStatus->CalPos6 = false;

    this->pButtonStatus->CalibrationDo = false;
    this->pButtonStatus->CalibrationSave = false;
}

void backinstance::onbtnClickedWorkType(){
    if(this->WorkType == ENUM_WorkType::Auto){
        this->WorkType = ENUM_WorkType::Mannual;
        this->WorkModel = ENUM_WorkModel::Null;
        this->pButtonStatus->Calibration = false;
        this->pButtonStatus->CalibrationDo = false;
        this->pButtonStatus->CalibrationSave = false;
        this->pButtonStatus->CalPos1 = false;
        this->pButtonStatus->CalPos2 = false;
        this->pButtonStatus->CalPos3 = false;
        this->pButtonStatus->CalPos4 = false;
        this->pButtonStatus->CalPos5 = false;
        this->pButtonStatus->CalPos6 = false;
        this->pButtonStatus->PointRecord = false;
        this->pButtonStatus->RobotUDPConnect = false;
        this->pButtonStatus->SeamFinding =false;
        this->pButtonStatus->SeamFindingStart2End = false;
        this->pButtonStatus->SeamPosCal = false;
        this->pButtonStatus->SeamTracking = false;
        this->pButtonStatus->TaskNull = true;
    }
    else{
        this->WorkType = ENUM_WorkType::Auto;
        this->WorkModel = ENUM_WorkModel::Null;
        this->pButtonStatus->Calibration = false;
        this->pButtonStatus->CalibrationDo = false;
        this->pButtonStatus->CalibrationSave = false;
        this->pButtonStatus->CalPos1 = false;
        this->pButtonStatus->CalPos2 = false;
        this->pButtonStatus->CalPos3 = false;
        this->pButtonStatus->CalPos4 = false;
        this->pButtonStatus->CalPos5 = false;
        this->pButtonStatus->CalPos6 = false;
        this->pButtonStatus->PointRecord = false;
        this->pButtonStatus->RobotUDPConnect = false;
        this->pButtonStatus->SeamFinding =false;
        this->pButtonStatus->SeamFindingStart2End = false;
        this->pButtonStatus->SeamPosCal = false;
        this->pButtonStatus->SeamTracking = false;
        this->pButtonStatus->TaskNull = true;
    }
}

void backinstance::onbtnClickedSeamPosCal(double (&PositionStart)[6], double (&PositionEnd)[6]){
    int i = 0;
    if(this->WorkModel == ENUM_WorkModel::SeamFinding || this->WorkModel == ENUM_WorkModel::SeamFindingStart2End){
        if(this->WorkType == ENUM_WorkType::Mannual){
            if(this->pLaserSensorData->bRecord == false){
                switch (WorkModel) {
                case ENUM_WorkModel::SeamFindingStart2End:
                        SeamFindingStart2EndProcessMannualCal();
                        for(i = 0; i<6; i++){
                            PositionStart[i] = this->pSeamFindingData->StartPos[i];
                            PositionEnd[i] = this->pSeamFindingData->EndPos[i];
                        }
                    break;
                default:
                    break;
                }

            }
        }
    }
}

void backinstance::onbtnClickedSeamPosReset(){
    this->pSeamFindingData->EndPointDone = false;
    this->pSeamFindingData->StartPointDone = false;
    this->vecLaserSeamDataByPCS.clear();
}

void backinstance::onbtnClickedSeamPosSend(){

}

void backinstance::onbtnClickedPointRecord(){
    if(this->pLaserSensorData->bRecord){
        this->pLaserSensorData->bRecord = false;
    }
    else{
        this->pLaserSensorData->bRecord = true;
    }

}

void backinstance::SeamTechTCPThreadLoopRun(){
    switch (this->WorkModel) {
        case ENUM_WorkModel::Null:
            break;
        case ENUM_WorkModel::Calibration:
            this->onSeamCalibrationProcess_Auto();
            break;
        case ENUM_WorkModel::SeamFinding:
            break;
        case ENUM_WorkModel::SeamFindingStart2End:
            this->onSeamFindingStart2EndProcess();
            break;
        case ENUM_WorkModel::SeamTracking:
            break;
    }
}

void backinstance::SeamTechUDPThreadLoopRun(){

}

void backinstance::onSeamTrackingProcess(){

}

void backinstance::onSeamFindingProcess(){

}

void backinstance::onSeamFindingStart2EndProcess(){
    if(this->WorkType == ENUM_WorkType::Auto){
        this->onSeamFindingStart2EndProcess_Auto();
    }
    else if(this->WorkType == ENUM_WorkType::Mannual){
        this->onSeamFindingStart2EndProcess_Mannual();
    }
}

bool backinstance::getButtonStatus(ENUM_ButtonName Name){
    bool tempbool;
    switch (Name) {
    case ENUM_ButtonName::RobotUDPConnect:
        tempbool = this->pButtonStatus->RobotUDPConnect;
        break;
    case ENUM_ButtonName::TaskNull:
        tempbool = this->pButtonStatus->TaskNull;
        break;
    case ENUM_ButtonName::Calibration:
        tempbool = this->pButtonStatus->Calibration;
        break;
    case ENUM_ButtonName::SeamFinding:
        tempbool = this->pButtonStatus->SeamFinding;
        break;
    case ENUM_ButtonName::SeamFindingStart2End:
        tempbool = this->pButtonStatus->SeamFindingStart2End;
        break;
    case ENUM_ButtonName::SeamTracking:
        tempbool = this->pButtonStatus->SeamTracking;
        break;
    case ENUM_ButtonName::CalPos1:
        tempbool = this->pButtonStatus->CalPos1;
        break;
    case ENUM_ButtonName::CalPos2:
        tempbool = this->pButtonStatus->CalPos2;
        break;
    case ENUM_ButtonName::CalPos3:
        tempbool = this->pButtonStatus->CalPos3;
        break;
    case ENUM_ButtonName::CalPos4:
        tempbool = this->pButtonStatus->CalPos4;
        break;
    case ENUM_ButtonName::CalPos5:
        tempbool = this->pButtonStatus->CalPos5;
        break;
    case ENUM_ButtonName::CalPos6:
        tempbool = this->pButtonStatus->CalPos6;
        break;
    case ENUM_ButtonName::CalibrationDo:
        tempbool = this->pButtonStatus->CalibrationDo;
        break;
    case ENUM_ButtonName::CalibrationSave:
        tempbool = this->pButtonStatus->CalibrationSave;
        break;
    case ENUM_ButtonName::PointRecord:
        tempbool = this->pButtonStatus->PointRecord;
        break;
    case ENUM_ButtonName::SeamPosCal:
        tempbool = this->pButtonStatus->SeamPosCal;
        break;
    }
    return tempbool;
}

